#pragma once

#include "singleton_container.h"

template<class T>
class SingletonDelegator {
public:
    SingletonDelegator()
    {
        nameT = __PRETTY_FUNCTION__;
        nameT = nameT.substr(nameT.find("T = "));
        nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = "));
        SingletonContainer::GetInstance()->AddSingleton(nameT, T::GetInstance());
    }

    template<class S>
    sptr<S> Dep()
    {
        std::string nameS = __PRETTY_FUNCTION__;
        nameS = nameS.substr(nameS.find("S = "));
        nameS = nameS.substr(sizeof("S ="), nameS.length() - sizeof("S = "));

        auto ret = SingletonContainer::Get<S>();
        if (ret != nullptr) {
            SingletonContainer::GetInstance()->DependOn(nameT, nameS);
        }
        return ret;
    }

private:
    std::string nameT;
};
